//
//  ViewController2.m
//  03.16-20202
//
//  Created by student on 16/3/16.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController2.h"

@interface ViewController2 ()
@property (weak, nonatomic) IBOutlet UIView *view1;

@property (weak, nonatomic) IBOutlet UITextField *textField1;
@property (weak, nonatomic) IBOutlet UITextField *textField2;
@property (weak, nonatomic) IBOutlet UITextField *textField3;
@end

@implementation ViewController2




- (void)viewDidLoad {
    [super viewDidLoad];
    [self show];
  
}
- (IBAction)btnBack:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)changeValue:(UISlider *)sender
{
    int value =sender.value;
    switch (sender.tag) {
        case 0:
            self.textField1.text=[NSString stringWithFormat:@"%i",value];
            break;
        case 1:
            self.textField2.text=[NSString stringWithFormat:@"%i",value];
            break;
        case 2:
            self.textField3.text=[NSString stringWithFormat:@"%i",value];
            break;
        default:
            break;
    }
    [self saveDta];
    [self show];
    
}
-(void)show
{
    NSUserDefaults *d=[NSUserDefaults standardUserDefaults];
    
    self.textField1.text= [d objectForKey:@"red"];
    self.textField2.text= [d objectForKey:@"green"];
    self.textField3.text= [d objectForKey:@"blue"];
    self.view1.backgroundColor=[UIColor colorWithRed:[self.textField1.text intValue]/255.0 green:[self.textField2.text intValue]/255.0 blue:[self.textField3.text intValue]/255.0 alpha:1.0];
}

-(void)saveDta
{
    NSUserDefaults *d=[NSUserDefaults standardUserDefaults];
    
    [d setObject:self.textField1.text forKey:@"red"];
    [d setObject:self.textField2.text forKey:@"green"];
    [d setObject:self.textField3.text forKey:@"blue"];
    
    [d synchronize];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

@end
